import readStream from "../utils/readStream.js"
const InjectScript = ({app,root})=>{
    let script =`window.process ={
        env:{
            NODE_ENV:'development'
        },
    }`
    app.use(async (ctx,next)=>{
        await next()
        if(ctx.response.is('html')){
            let html = await readStream(ctx.body)
            console.log(html,'html')
            html = html.replace(/<head>/,`<head><script>${script}</script>`)
            ctx.body = html
        }
    })

}
export default InjectScript